// =====================================================================
//
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
// =====================================================================
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk.Temporary;

namespace Microsoft.Crm.Sdk.Messages
{
	/// <summary>
	/// A copy of Scheduling.SearchDirection enum.
	/// </summary>
	// Note: must be in sync with Scheduling.SearchDirection enum.
	[DataContract(Namespace = "http://schemas.microsoft.com/crm/2011/Contracts")]
	public enum SearchDirection
	{
		[EnumMember]
		Forward,

		[EnumMember]
		Backward
	}

	/// <summary>
	/// Defines an AppointmentRequest in Services layer.
	/// </summary>
	[DataContract(Namespace = "http://schemas.microsoft.com/crm/2011/Contracts")]
	public sealed class AppointmentRequest : IExtensibleDataObject
	{
		/// <summary>
		/// Even though this constructor does not do anything, it is still needed because 
		/// XmlSerializer requires public default constructor on the class to be serialized.
		/// </summary>
		public AppointmentRequest()
		{
			this.SearchWindowStart = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc);
			this.SearchWindowEnd = new DateTime(9999, 12, 30, 23, 59, 59, DateTimeKind.Utc);
			this.AppointmentsToIgnore = new AppointmentsToIgnore[0];
			this.RequiredResources = new RequiredResource[0];
			this.Constraints = new ConstraintRelation[0];
			this.Objectives = new ObjectiveRelation[0];
			this.Sites = new Guid[0];
		}

		/// <summary>
		/// Id of the service being requested.
		/// </summary>
		[DataMember]
		public Guid ServiceId { get; set; }

		/// <summary>
		/// Offset in minutes from midnight
		/// </summary>
		[DataMember]
		public int AnchorOffset { get; set; }

		/// <summary>
		/// User time zone Name for the search
		/// </summary>
		[DataMember]
		public int UserTimeZoneCode { get; set; }

		/// <summary>
		/// Duration of recurrence pattern in minutes
		/// </summary>
		[DataMember]
		public int RecurrenceDuration { get; set; }

		/// <summary>
		/// Time zone of recurrence pattern
		/// </summary>
		[DataMember]
		public int RecurrenceTimeZoneCode { get; set; }

		/// <summary>
		/// Array of AppointmentsToIgnore objects.
		/// Each element contains an array of appointments per resource to be ignored by scheduling engine. 
		/// </summary>
		[DataMember]
		[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Needed to ensure backward compatibility")]
		public AppointmentsToIgnore[] AppointmentsToIgnore { get; set; }

		/// <summary>
		/// Array of RequiredResource objects.
		/// </summary>
		[DataMember]
		[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Needed to ensure backward compatibility")]
		public RequiredResource[] RequiredResources { get; set; }

		/// <summary>
		/// Start of the search window.
		/// </summary>
		[DataMember]
		public DateTime? SearchWindowStart { get; set; }

		/// <summary>
		/// End of the search window.
		/// </summary>
		[DataMember]
		public DateTime? SearchWindowEnd { get; set; }

		/// <summary>
		/// Start of search recurrence rule - relative to RecurrenceTimeZone.
		/// </summary>
		[DataMember]
		public DateTime? SearchRecurrenceStart { get; set; }

		/// <summary>
		/// Rule defining search's recurrence pattern.
		/// Null for no recurrence pattern.
		/// </summary>
		[DataMember]
		public string SearchRecurrenceRule { get; set; }

		/// <summary>
		/// Duration of the service in minutes. 0 indicates that the default should be used.
		/// Otherwise, overrides the service's default.
		/// </summary>
		[DataMember]
		public int Duration { get; set; }

		/// <summary>
		/// Array of ConstraintRelation objects defining constraints of the request.
		/// </summary>
		[DataMember]
		[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Needed to ensure backward compatibility")]
		public ConstraintRelation[] Constraints { get; set; }

		/// <summary>
		/// Array of ObjectiveRelation objects defining objectives of the request.
		/// </summary>
		[DataMember]
		[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Needed to ensure backward compatibility")]
		public ObjectiveRelation[] Objectives { get; set; }

		/// <summary>
		/// Direction of the search.
		/// </summary>
		[DataMember]
		public SearchDirection Direction { get; set; }

		/// <summary>
		/// Number of results desired.
		/// </summary>
		[DataMember]
		public int NumberOfResults { get; set; }

		/// <summary>
		/// Sites that the service performs.
		/// Empty means search for proposal on any sites.
		/// </summary>
		[DataMember]
		[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Needed to ensure backward compatibility")]
		public Guid[] Sites { get; set; }


		#region IExtensibleDataObject Implementation
		private ExtensionDataObject _extensionDataObject;
		public ExtensionDataObject ExtensionData
		{
			get
			{
				return _extensionDataObject;
			}
			set
			{
				_extensionDataObject = value;
			}
		}
		#endregion IExtensibleDataObject Implementation
	}
}
